package com.xsl.culture.mybasevideoview.utils;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.xsl.culture.R;
import com.xsl.culture.mybasevideoview.CustomApp;


/** 
 * description:
 * author: Allen
 * date:
 */
public class ToastUtil {

    private static Toast mToast;

    public static void show(String msg) {
        if (mToast == null) {
            mToast = Toast.makeText(CustomApp.get(), msg, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(msg);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    public static void centerToast(String msg) {
        Toast toast2 = new Toast(CustomApp.get());
        View view = LayoutInflater.from(CustomApp.get()).inflate(R.layout.cent_toast, null);
        TextView textView = view.findViewById(R.id.msg);
        textView.setText(msg);
        toast2.setView(view);
        toast2.setDuration(Toast.LENGTH_LONG);
        toast2.setGravity(Gravity.CENTER, 0, 0);
        toast2.show();
    }

    public static void centerToast(int msg) {
        Toast toast2 = new Toast(CustomApp.get());
        View view = LayoutInflater.from(CustomApp.get()).inflate(R.layout.cent_toast, null);
        TextView textView = view.findViewById(R.id.msg);
        textView.setText(msg);
        toast2.setView(view);
        toast2.setDuration(Toast.LENGTH_LONG);
        toast2.setGravity(Gravity.CENTER, 0, 0);
        toast2.show();
    }

    public static void show(int msg) {
        if (mToast == null) {
            mToast = Toast.makeText(CustomApp.get(), msg, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(msg);
            mToast.setDuration(Toast.LENGTH_LONG);
            mToast.setGravity(Gravity.CENTER, 0, 0);
        }
        mToast.show();
    }

    public static void cancelToast() {
        if (mToast != null) {
            mToast.cancel();
        }
    }

}
